<?php 
ini_set('date.timezone','Asia/Shanghai');
class dbli{
    /* 数据库链接 */
    public $con;
    /* 构造方法连接数据库 */
    public function __construct($conf) {
        $con=new mysqli( $conf ['DBhost'], $conf ['DBname'], $conf ['DBpasswd'],$conf ['DBbase'],3306);
        mysqli_query($con, 'set names utf8');
        $this->con = $con;
    }

    /* count */
    public function count($sql) {
        $query =mysqli_query($this->con, $sql);
        $result=  mysqli_fetch_array($query);
        return $result [0];
    }

    /* 数据库添加方法 */
    public function add($sql) {
        mysqli_query($this->con, $sql);
        $rc = mysqli_affected_rows($this->con);
        if ($rc > 0) {
            return mysqli_insert_id( $this->con );
        } else {
            return 0;
        }
    }

    /* mysql 查询 */
    public function select($sql) {
        $result =  mysqli_query($this->con, $sql);
        $arr=array();
        while ( $row =@ mysqli_fetch_assoc( $result ) ) {
            $arr [] = $row;
        }
        return $arr;
    }

    /* mysql 增改 */
    public function U_D($sql) {
        $result = mysqli_query($this->con, $sql);
        return mysqli_affected_rows ( $this->con );
    }
    /* 获取mysql 错误 */
    public function error() {
        return $this->con->error;
    }

}

    $array=array(
        /*数据库主机  */
        'DBhost'=>'localhost',
        /*数据库名  */
        'DBbase'=>'weixin',
        /*数据账号名  */
        'DBname'=>'root',
        /* 数据库密码 */
        'DBpasswd'=>'',
    );
    
    $db=new dbli($array);
    $sql="select issue,numbers,gtime from pks_k where games=2 and gtime<".time()." order by gtime desc limit 0,1";
    $arr=$db->select($sql);
    $current=array(
        'qihao' => $arr[0]['issue']%1000,
        'awardTime' =>date('Y-m-d H:i:s',$arr[0]['gtime']),
        'awardNumbers' =>$arr[0]['numbers'],
    );
    
  $nowdata=date('Y-m-d',strtotime(date('Y-m-d'))+3600*24)."  00:04:15";

   if($current['qihao']>=180){
       $xqh=132;
        $nowdata=date('Y-m-d',strtotime(date('Y-m-d'))+3600*24)." 00:04:15";
        $times= strtotime($nowdata);
   }else{
        $times=$arr[0]['gtime']+300;
        $xqh=$current['qihao']+1;
    }
    $dat=$times-time()<0?0:$times-time();
    $next=array('qihao' =>$xqh,
        'awardTime'=>date('Y-m-d H:i:s',time()),
        'awardTimeInterval' =>$dat,'delayTimeInterval' =>$times-time()<0?0:$times-time()-21);
    $array=Array('time' => time(),'current' =>$current,'next'=>$next);
    echo json_encode($array);
    
    /*{"time":1484189645,"current":{"qihao":"180","awardTime":"2017-01-12 04:04:00","awardNumbers":"5,2,6,8,1,7,3,4,9,10"},"next":{"qihao":"001","awardTime":"2017-01-12 04:09:30","awardTimeInterval":7975000,"delayTimeInterval":15}}  */
    
?>